﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

using Telerik.Windows.Controls;
using SaleLibrary.Score;
using BrokerBase.Lib.Core;

namespace Broker.Mgr.SaleView
{
    /// <summary>
    /// Interaction logic for ScoreExchangeRecordForm.xaml
    /// </summary>
    public partial class ScoreExchangeRecordForm
    {
        private IScoreRecord record;

        public ScoreExchangeRecordForm(IScoreRecord record)
            : base()
        {
            this.record = record;
            InitializeComponent();
            Loaded += new RoutedEventHandler(ScoreExchangeRecordForm_Loaded);
        }

        void ScoreExchangeRecordForm_Loaded(object sender, RoutedEventArgs e)
        {

            DataContext = record;
        }

        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            if (!Verify())
            {
                return;
            }

            try
            {

                IBaseService<ScoreRecord> svr = new BaseService<ScoreRecord>(AppGlobal.HbmSessionFactory.GetCurrentSession());
                MessageBox.Show("保存成功!");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "提示");
            }

        }

        private void btnExit_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }

        private bool Verify()
        {
            if (record.RecordType == null)
            {
                MessageBox.Show("请输入兑换类型!");
                return false;
            }

            if (record.Score <= 0)
            {
                MessageBox.Show("兑换的积分必须大于零!");
                return false;
            }

            if (record.Score > record.Client.TotalScore)
            {
                MessageBox.Show("兑换的积分不能大于现有的积分!");
                return false;
            }

            return true;
        }
    }
}
